//
// Created by jsjxsy on 2022/6/24.
//
#include <stdio.h>

void writeFile(const char *fileName) {
    FILE *f;
    f = fopen(fileName, "w+");
    if (f) {
        fprintf(f, "what is your name?\nmy name is %s \n", "xsy");
        int byte_size = fprintf(f, "how old you?\n%d years old \n", 10);
        if (byte_size > 0) {
            printf("size count:%d \n", byte_size);
            puts("write file is success!");
        }
        fclose(f);
    } else {
        perror("open file error");
    }
}

void readFile(const char *fileName) {
    char str1[10];
    char str2[10];
    FILE *f;
    f = fopen(fileName, "r+");
    if (f) {
        int args_count = fscanf(f, "%s %s", str1, str2);
        if (args_count != EOF) {
            printf("args count:%d \n", args_count);
            puts("read file success");
        }
        fclose(f);
    } else {
        perror("open file error");
    }
    printf("Read str1 |%s|\n", str1);
    printf("Read str2 |%s|\n", str2);
}


int main() {
//    writeFile("data/test_print.txt");
//    readFile("data/test_print.txt");
    fprintf(stderr, "the error info: %s \n", "file is not exist");
    fprintf(stdout, "the message info: %s \n", "this is normal message");
    return 0;
}